/**
 * DOM 操作封装
 */

function getEle(selector) {
    return document.querySelector(selector)
}
function getEles(selector) {
    return document.querySelectorAll(selector)
}

function ready(callback) {/* 加载事件，加载完成后触发 */
    window.addEventListener('DOMContentLoaded', callback)
}



// 封装文档加载事件
function ready(callback) {
    // onload事件:当所有资源加载完成之后才执行js代码
    // DOMcontentLoaded事件当dom加载完成之后可以执行代码,加载速度快一些
    window.addEventListener('DOMContentLoaded', callback)
}
//封装页脚
function bMenu(val) {
    getEle('body').innerHTML +=
        `<footer>
    <ul class="fdrow tcenter">
        <li class="${val=='home'?'active':''}"><a href="home.html" class="fdcolumn"><i class="iconfont icon-shouyeshouye"></i><span>首页</span></a></li>
        <li class="${val=='sports'?'active':''}" ><a href="sports.html" class="fdcolumn"><i class="iconfont icon-yundong-"></i><span>运动</span></a></li>
        <li class="${val=='circle'?'active':''}" ><a href="circle.html" class="fdcolumn"><i class="iconfont icon-quanzi"></i><span>圈子</span></a></li>
        <li class="${val=='mine'?'active':''}" ><a href="mine.html" class="fdcolumn"><i class="iconfont icon-dongtai"></i><span>我的</span></a></li>
    </ul>
</footer>`


}
// 封装头部
function tMenu(val) {
    getEle('header').innerHTML =
        `
    <ul class="fdrow tcenter">
    <li class="${val=='sports'?'active':''}" ><a href="sports.html" class="fdcolumn"><span>跑步</span></a></li>

        <li class="${val=='ride'?'active':''}"><a href="ride.html" class="fdcolumn"><span>骑行</span></a></li>
        <li class="${val=='course'?'active':''}" ><a href="course.html" class="fdcolumn"><span>课程</span></a></li>
    </ul>
`


}
// 检测是否登录
// 如果已登录,用户可以自由切换页面,如未登录不能进入到界面
function isLogin(){
    if(!localStorage.getItem('tk')){
        window.location.href='login.html'
    }
}

//暴露出去
module.exports = {
    getEle,
    getEles,
    ready,
    bMenu,
    isLogin,
    tMenu
}

